#! /bin/sh

echo >&2 "running: $0 $*"
echo >&2 '$'"RESALLOC_NAME: $RESALLOC_NAME"

cmd=(
    /usr/bin/resalloc-aws-new
      --aws-profile default
      --ami {{ copr_builder_images.aws[item] }}
      --ssh-key-name copr-builder
      --security-group-id sg-0c3efdb681ced5d4f
      --debug
{% for subnet in aws_arch_subnets[item] %}
      --possible-subnet {{ subnet }}
{% endfor %}
{% if item == 'x86_64' %}
      --instance-type i3.large
{% else %}
      --instance-type a1.xlarge
{% endif %}
      --tag FedoraGroup=copr
      --tag CoprPurpose=builder
      --tag CoprInstance={% if devel %}devel{% else %}production{% endif %}
      --tag arch={{ item }}
      --playbook /var/lib/resallocserver/provision/builderpb-aws.yml
)

set -x
# execute the command + additional arguments
exec "${cmd[@]}" "$@"
